<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>请假列表</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="../Styles/admin-all.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/base.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="../Styles/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Styles/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Styles\laypage\laypage.js"></script>
    <style type="text/css">
        #leave{
            width: 80%;
            height: 60%;
            margin: auto;
            margin-top: 30px;
        }
        #page{
        	float:right;
        }
    </style>
</head>
<body>
<div id="leave" class="view">
    <h2 style="margin-bottom: 20px;background: oldlace;height: 50px;padding-top: 8px">请假管理</h2>
    <div id="lea">
        <form action="" class="form-search">
            <div class="input-group" style="margin-bottom: 10px;width: 500px;float: right;">
                <input id="inp" class="form-control" type="text" value="" placeholder="请输入申请人姓名或者审批状态"/>
                <span class="input-group-btn">
                	<button type="button" class="btn" id="btn">查找</button>
                </span>
                
            </div>
            <div><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleModal">清理数据</button></div>

            <table class="table table-hover">
                <thead>
                    <tr class="info"><th colspan="9">请假申请列表</th></tr>
                    <tr class="info"><th><input type="checkbox" id="allChecked" name="allChecked" onclick="check_all()"/></th><th>序号</th><th>申请人</th><th>部门名称</th><th>申请时间</th><th>请假天数</th><th>结束时间</th><th>状态</th><th>操作</th></tr>
                </thead>
                <tbody id="lea1">
                    
                </tbody>
            </table>
            <div id="page"></div>
        </form>
    </div>

	<!-- 删除模态框（Modal） -->
	<div class="modal fade" id="deleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">温馨提示</h4>
				</div>
				<div class="modal-body">您确定清理这些数据吗？？？？	</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" data-dismiss="modal" id="moredel">确定</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	
</div>
<script type="text/javascript">
	console.log("123");
	var usp=$("#usp").val();
	var currentPage=1;
        $(function(){
        	
        	//删除  批量删除
        	$(document).on('click','#moredel',function(){
        		obj=document.getElementsByName("m");
        		check_val=[];
        		var str="";
        		for(i in obj){
        			if(obj[i].checked){
        				str+=obj[i].value+","
        				check_val.push(obj[i].value);
        				
        			}
        		}
        		console.log(str)
        		if(str==''){
        			alert("您选择的数据未审批或者您还没有选择数据！！！！！");
        		}else{
        			$.ajax({
        				url:'../show/deleteMore',
        				data:{'str':str},
        				dataType:'json',
        				type:'post',
        				success:function(res){
        					alert("删除成功");
        					getLea();
        				}
        			})
        		}
        		
        	});
        	
        	getLea(usp);
        	console.log("456");
        	
        	function getLea(){
        		console.log(usp);
        		
        		$.ajax({
            		url:"../show/showLea",
            		type:"post",
            		data:{"usp":usp,"currentPage":currentPage},
            		dataType:"json",
            		
            		success:function(result){
            			console.log(result);
            			var status=null;
            			var handle=null;
            			 $("#lea1").html("");
            			 $.each(result.leaList,function(inx,ele){
            				 console.log(ele.deptname);
            				 if(ele.l_status==0){
            					 status="未审批";
            					 handle="<a href='../show/findlea?l_id="+ele.l_id+"'>审批</a>";
            					 $("#lea1").append(
              							"<tr class='warning'><td><input type='checkbox' name='wm' id='wm'/></td><td>"+(inx+1)+"</td><td><a href='../show/showLeave?l_id="+ele.l_id+"'>"+ele.l_user+"</a></td><td>"+ele.deptname+"</td><td>"+ele.l_time+"</td><td>"+ele.l_day+"</td><td>"+ele.l_end+"</td><td>"+status+"</td><td>"+handle+"</td></tr>"
              					 )
            				 }else if(ele.l_status==1){
            					 status="审批通过";
            					 handle="<a href='../show/deleteLea?l_id="+ele.l_id+"'>删除</a>";
            					 $("#lea1").append(
              							"<tr class='success'><td><input type='checkbox' name='m' value='"+ele.l_id+"'/></td><td>"+(inx+1)+"</td><td><a href='../show/showLeave?l_id="+ele.l_id+"'>"+ele.l_user+"</a></td><td>"+ele.deptname+"</td><td>"+ele.l_time+"</td><td>"+ele.l_day+"</td><td>"+ele.l_end+"</td><td>"+status+"</td><td>"+handle+"</td></tr>"
              					 )
            				 }else{
            					 status="审批不通过";
            					 handle="<a href='../show/deleteLea?l_id="+ele.l_id+"'>删除</a>";
            					 $("#lea1").append(
              							"<tr class='error'><td><input type='checkbox' name='m' value='"+ele.l_id+"'/></td><td>"+(inx+1)+"</td><td><a href='../show/showLeave?l_id="+ele.l_id+"'>"+ele.l_user+"</a></td><td>"+ele.deptname+"</td><td>"+ele.l_time+"</td><td>"+ele.l_day+"</td><td>"+ele.l_end+"</td><td>"+status+"  <span style='font-size:6px;font-style:italic'>假由:"+ele.l_style+"</span></td><td>"+handle+"</td></tr>"
              					 )
            				 }
            				 
            				 laypage({
            					  cont: $("#page"),  //容器
            					  pages: result.pages, //总页数
            					  curr:currentPage,     //当前页, 
            					  skin: 'molv', //皮肤
            					  skip:true, //支持跳页的功能
            					  last:'尾页',
            					  groups:2,  //多少页进行分组
            					  jump: function(obj, first){ //触发分页后的回调
            						currentPage = obj.curr;
            					    if(!first){   //一定要加此判断，否则初始时会无限刷新
            					      getLea();  //获取当前页
            					    }
            					  }
            					});
         				 })
            		}
            	})
        	};
        	
        	$("#btn").click(function(){
      		   usp=$("#inp").val();
      		   console.log(usp);
      		   getLea();
      		   
      	   })
        	
        });
        
        /*全选/反选触发函数*/
    	function check_all(){
    	     var del = document.getElementById("allChecked").checked;
    	     var arrState = document.getElementsByName("m");
    	    
    	     for(var i = 0;i<arrState.length;i++){
    	            arrState[i].checked = del;	            
    	     }
    	 }
      
</script>
</body>

</html>